Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Replace CHECK() with CHECK_*() so that when a check is failing, more … #2847

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nwangtw
Copy link
Contributor

@nwangtw nwangtw commented Apr 3, 2018

so that when a check is failing, more useful information is logged.

This PR affects only the CHECK() calls in cpp files.

Copy link
Contributor

@Yaliang Yaliang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are looking into those logging messages to be informative. Would you update each check with a descriptive message?

CHECK_EQ(a, b) << ": some crazy thing is happening"

Also give a before|after example will also be useful for reviews

@nwangtw
Copy link
Contributor Author

nwangtw commented Apr 4, 2018

Yeah. It is a good point.

I was changing the safe ones only in this PR to be quick. For the CHECK_EQ() << "...." case I need to do some tests to verify the behavior of the library. Let me see if I can find some time to run the tests.

@nwangtw
Copy link
Contributor Author

nwangtw commented Apr 4, 2018

Just did a test. Seems the checks work with << as expected.

Run 1:
int a = 1, b = 2;
CHECK(a > b) << "Failing check 'a > b'";

The output is:
Check failed: a > b Failing check 'a > b'

Run 2:
int a = 1, b = 2;
CHECK_GT(a, b) << "Failing check 'gt(a,b)'";

The output is:
Check failed: a > b (1 vs. 2) Failing check 'gt(a, b)'

Let me update the checks with << operator then.

@Yaliang
Copy link
Contributor

Yaliang commented Apr 4, 2018

Just pass you a document for glog: http://rpg.ifi.uzh.ch/docs/glog.html

@nwangtw
Copy link
Contributor Author

nwangtw commented Apr 4, 2018

And I will see what description I can add now.

@nwangtw
Copy link
Contributor Author

nwangtw commented Apr 4, 2018

Cool. Thx. @Yaliang

@nwangtw
Copy link
Contributor Author

nwangtw commented Apr 5, 2018

Updated descriptions

Copy link
Contributor

@Yaliang Yaliang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a logic change in the code, some incorrect message I believe is caused copying between lines?

In addition, I would prefer the way like Failed to find xxxx instead of xxx is not found in xxx list. Check other log messages, it favors a way like (I) did something or (I'm) doing something.

disableRateLimit(); // To free the config object
bufferevent_free(buffer_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's either unrelated change or need to be rebased

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. It is an unrelated change and has been merged in a different PR.

@@ -245,7 +245,7 @@ class Client : public BaseClient {
__global_protobuf_pool_release__(m);
return;
}
CHECK(m->IsInitialized());
CHECK(m->IsInitialized()) << "Protobuf not initialized";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't m represents a Message ?

@@ -131,7 +131,7 @@ ZKClient::ZKClient(const std::string& hostportlist, EventLoop* eventLoop,
: eventLoop_(eventLoop),
hostportlist_(hostportlist),
client_global_watcher_cb_(std::move(global_watcher_cb)) {
CHECK(client_global_watcher_cb_);
CHECK(client_global_watcher_cb_) << "Client global watcher is not provided";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to explicitly say it's a callback

active_ = true;
}

void BoltInstance::Deactivate() {
LOG(INFO) << "Not doing anything in Bolt Dacctivate";
CHECK(active_);
CHECK(!active_) << "Bolt instance is not active";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic changed:

CHECK(active_) << "Bolt instance is not active"

VCallback<> watcher) {
CHECK(watcher);
CHECK(!topology_name.empty());
VCallback<> watcher) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated indent change

@@ -59,17 +59,17 @@ void XorManager::rotate(EventLoopImpl::Status) {
}

void XorManager::create(sp_int32 _task_id, sp_int64 _key, sp_int64 _value) {
CHECK(tasks_.find(_task_id) != tasks_.end());
CHECK(tasks_.find(_task_id) != tasks_.end()) << "Task " << _task_id << " is not found";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer Failed to find Task xxx

@@ -1085,7 +1085,7 @@ void StMgr::RestoreTopologyState(sp_string _checkpoint_id, sp_int64 _restore_txi
void StMgr::StartStatefulProcessing(sp_string _checkpoint_id) {
LOG(INFO) << "Received StartProcessing message from tmaster for "
<< _checkpoint_id;
CHECK(stateful_restorer_);
CHECK(stateful_restorer_) << "Stateful restorer doesn't exist when starting process";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe starting stateful process

@@ -348,7 +348,7 @@ void StMgr::CreateCheckpointMgrClient() {
}

void StMgr::CreateTMasterClient(proto::tmaster::TMasterLocation* tmasterLocation) {
CHECK(!tmaster_client_);
CHECK(!tmaster_client_) << "TMaster client has already existed";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TMaster Client? and also change next line Tmaster Client to TMaster Client?

@@ -282,7 +282,7 @@ void StMgr::FetchMetricsCacheLocation() {
}

void StMgr::StartStmgrServer() {
CHECK(!stmgr_server_);
CHECK(!stmgr_server_) << "Stmgr server is already running";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StmgrServer is already running? to keep the same way as the next line.

@@ -131,7 +131,7 @@ StMgrClient* StMgrClientMgr::CreateClient(const sp_string& _other_stmgr_id,
bool StMgrClientMgr::SendTupleStreamMessage(sp_int32 _task_id, const sp_string& _stmgr_id,
const proto::system::HeronTupleSet2& _msg) {
auto iter = clients_.find(_stmgr_id);
CHECK(iter != clients_.end());
CHECK(iter != clients_.end()) << "Stmgr " << _stmgr_id << " is not found in client list";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer Failed to find the client to Stmgr xxx

@nwangtw
Copy link
Contributor Author

nwangtw commented Apr 18, 2018

Thanks for reviewing.

This was a super quick PR and incremental improvement. It seems to be more time consuming now. I will leave this PR here for now and come back when I have the time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants